function f = gammafuncAR2(T,beta, M, pxest)

xl = 2; yval = 1; % doesn't matter what these are set to.

v_crime_bar_big = 999*ones(M,2);
for val = 1:2
    x = val-1;
    v_crime_bar = x*ones(M,1);
extp=x*ones(M,1);
extpL=xl*ones(M,1);
for m=1:M
B = 1;
for t=2:T 
extpL(m) =  extp(m);    
extp(m) =  pxest(1,m) + pxest(2,m)*extp(m)  + pxest(3,m)*(yval+t-1) + pxest(4,m)*extpL(m) ;
temp = beta^(t-1);
B = B+temp;
v_crime_bar(m) = v_crime_bar(m) + temp*extp(m);
end
end
v_crime_bar = v_crime_bar/B;
v_crime_bar_big(:,val) = v_crime_bar;
end

theta1ar2 = v_crime_bar_big(:,2) - v_crime_bar_big(:,1);
f = theta1ar2;
